/*
 * List.java  0.4.0 / Oct 26, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing;

import java.util.Vector;

import com.cute4j.swing.list.ArrayListModel;
import com.cute4j.swing.list.EmptyListModel;
import com.cute4j.swing.list.ListModel;
import com.cute4j.swing.list.VectorListModel;
import com.cute4j.swing.properties.ListProperties;

/**
 * List Component.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class List extends Component implements ListProperties {

  // TODO: finish

// Static Initialization. ------------------------------------------------------

  static {
    _initialize();
  }

// Package-Private Fields. -----------------------------------------------------

  ListModel model;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new List object.
   */
  public List() {
    this(new EmptyListModel());
  }

  /**
   * Constructs new List object.
   *
   * @param listData the list data
   */
  public List(Object[] listData) {
    this(new ArrayListModel(listData));
  }

  /**
   * Constructs new List object.
   *
   * @param listData the list data
   */
  public List(Vector listData) { // NOPMD
    this(new VectorListModel(listData));
  }

  /**
   * Constructs new List object.
   *
   * @param model the list model
   */
  public List(ListModel model) { // NOPMD - temp
    super(false); // TODO: remove
    throw new RuntimeException("Not implemented"); // TODO: Implement, NOPMD
    /*if (model == null) {
      throw new IllegalArgumentException("Null model");
    }
    this.model = model;*/
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Sets list model.
   *
   * @param model the model
   */
  public void setModel(ListModel model) {
    if (model == null) {
      throw new IllegalArgumentException("Null model");
    }
    ListModel oldModel = this.model;
    if (!oldModel.equals(model)) {
      _setModel(_delegate, model);
      this.model = model;
      firePropertyChange(PROPERTY_MODEL, oldModel, model);
    }
  }

// Package-Private Native Methods. ---------------------------------------------

  native long _create();

  native void _setModel(long delegate, ListModel model);

// Private Static Native Method. -----------------------------------------------

  private static native void _initialize();

}
